//
//  ShowPikerUIview.m
//  布丁动画项目
//
//  Created by apple on 15/10/9.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "ShowPikerUIview.h"
#import "Masonry.h"
@interface ShowPikerUIview()<UIPickerViewDataSource,UIPickerViewDelegate>
@end

@implementation ShowPikerUIview

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        UIPickerView *pigeview = [[UIPickerView alloc]init];
        
        UIView *v = [[UIView alloc]init];
        v.backgroundColor = [UIColor whiteColor];
        [self addSubview:v];

        pigeview.dataSource = self;
        pigeview.delegate = self;
        pigeview.backgroundColor = [UIColor whiteColor];
      

        [self addSubview:pigeview];
        
        _yesBnt = [UIButton buttonWithType:UIButtonTypeSystem];
        [_yesBnt setTitle:@"确定" forState:UIControlStateNormal];
        _yesBnt.tintColor = [UIColor orangeColor];
        
        [v addSubview:_yesBnt];
        
        _noBnt = [UIButton buttonWithType:UIButtonTypeSystem];
        [_noBnt setTitle:@"取消" forState:UIControlStateNormal];
        
        [v addSubview:_noBnt];
        
        [pigeview mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.mas_left);
            make.width.equalTo(self.mas_width);
            make.bottom.equalTo(self.mas_bottom);
            make.top.equalTo(self.mas_centerY).offset(80);
            
                   }];
        
        
        [v mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(pigeview.mas_top).offset(-50);
            make.width.equalTo(self.mas_width);
            make.height.equalTo(@50);
        }];
        
        [_yesBnt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(v.mas_centerY);
            make.right.equalTo(v.mas_right).offset(-10);
        }];
        
        [_noBnt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(v.mas_centerY);
            make.left.equalTo(v.mas_left).offset(10);
        }];

        
        
        
    }



    return self;

}

//列数,每一行上有所少个内容
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

//每列个数，有多少个内容
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    if (_number%25==0) {
        return _number/25;
    }
    return _number/25+2;
}

//每列宽度,内容的宽度
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{    
    return 200;
}

////返回选中行,用户选择
//-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
//
//    NSLog(@"hahhah");
//}

//给显示内容
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    NSString *str;
    _a = 1+25*row;
    
    _b = _a+24;
    
    if (_b>_number) {
        _b = _number;
        
    }
   str  = [NSString stringWithFormat:@"%ld --- %ld",_a,_b];
    
    if (_a == _number) {
        str = [NSString stringWithFormat:@"%ld",_a];
    }
    
    if (row == _number/25+1) {
        str = @"  ";
    }
    
    return str;
}


@end
